using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;

namespace TheWorldOfKongfuEasyMod;

[HarmonyPatch(typeof(StatusSub5))]
[HarmonyPatch("OnButtonClick")]
public static class Patch_StatusSub5_OnButtonClick
{
    static bool Prefix(ref StatusSub5 __instance, CharaData ___curdata, GameObject go)
    {
        if (SharedData.Instance(false).m_OpenDetail.Length > 0)
        {
            return false;
        }
        string[] array = go.name.Split('|');
        if (go == null || !go.activeInHierarchy || go.GetComponent<Button>() == null || !go.GetComponent<Button>().IsInteractable())
        {
            return false;
        }
        var mPackageController = SharedData.Instance(false).m_PackageController;
        var equipBtnData = mPackageController.gameObject.GetComponent<EquipBtnData>();
        if (!equipBtnData)
        {
            equipBtnData = mPackageController.gameObject.AddComponent<EquipBtnData>();
        }

        if (array[0] == "Learn")
        {
           
            equipBtnData.currentSlotName = ___curdata.m_Training_Id;
            return true;
        }

        return true;
    }
}